#include "hwm.h"
#include "map.h"
#include "hlog.h"

xcb_errors_context_t *g_err_ctx = NULL;
hashmap *g_map = NULL;
int main(int argc, char *argv[])
{
        xcb_connection_t *conn;
        int screen_nbr;
        char *display_name;

        if (argc < 2) {
                display_name = NULL;
        } else {
                display_name = argv[1];
        }

        g_map = hashmap_create();
        conn = xcb_connect(display_name, &screen_nbr);
        int error = xcb_connection_has_error(conn);
        if (error != 0) {
                hlog("Cannot connect display, code[%d]", error);
                exit(EXIT_FAILURE);
        }

        if (xcb_errors_context_new(conn, &g_err_ctx) == -1) {
                hlog("Cannot create error context");
                exit(EXIT_FAILURE);
        }
        run(conn, screen_nbr);
        xcb_errors_context_free(g_err_ctx);
        hashmap_free(g_map);
        xcb_disconnect(conn);
        hlog("Disconnet from %p\n", conn);
        return 0;
}